Make RequestFlags immutable with replace method#23
Merged
Conversation
xmartinez
approved these changes
Apr 8, 2026
xmartinez
left a comment
There was a problem hiding this comment.
LG!
nit: We should also update README.md (it references flags.copy()).
| /// | ||
| /// Note: passing `None` explicitly for an optional field (e.g. `cache_ttl=None`) | ||
| /// keeps the existing value rather than unsetting it. To unset an optional field, | ||
| /// construct a new `RequestFlags` directly. |
There was a problem hiding this comment.
This could be confusing, but for common use cases (e.g., ttl override), it should be fine.
9ac710e to
94522c5
Compare
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation / Description
The
RequestFlagsclass was previously mutable, allowing fields to be modified after creation.Routers and layers above meta-memcache-socket often share a single request flags object to avoid re-creating it, and we had a bug in the gutter pool where it was modifying the passed request flags that was shared across threads and requests.
This change makes
RequestFlagsimmutable to improve safety and predictability, while providing areplace()method for conveniently creating modified copies.Changes introduced
RequestFlagsimmutable by marking it asfrozenand removing field settersFinaltype annotations to all fields in the Python type stubcopy()method with a newreplace()method that accepts keyword arguments for selectively overriding fieldsreplace()method preserves existing values for unspecified fields and handles optional fields appropriatelyreplace()functionality and immutability behavior